package org.apache.commons.graph.collections

import kotlin.jvm.JvmField

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
 * The [DisjointSet] internal node representation.
 *
 * @param <E> the type of elements held in this node
</E> */
internal class DisjointSetNode<E>
/**
 * Creates a new [DisjointSet] node with the given value.
 *
 * @param element the node value has to be stored.
 */(
    /**
     * The stored node value.
     */
    @JvmField val element: E
) : Comparable<DisjointSetNode<E>> {
    /**
     * Returns the adapted element by this node.
     *
     * @return the adapted element by this node.
     */

    /**
     * Returns the reference to the parent node, the node itself by default.
     *
     * @return the reference to the parent node, the node itself by default.
     */
    /**
     * Sets the reference to a new parent node.
     *
     * @param parent the reference to a new parent node.
     */
    /**
     * The `DisjointSetNode` parent node, `this` by default.
     */
    @JvmField
    var parent: DisjointSetNode<E> = this

    /**
     * Returns this node rank.
     *
     * @return this node rank
     */
    /**
     * Sets a new different rank.
     *
     * @param rank the new rank to this node.
     */
    /**
     * The current node rank.
     */
    var rank: Int = 0

    /**
     * {@inheritDoc}
     */
    override fun compareTo(other: DisjointSetNode<E>): Int {
        return rank.compareTo(other.rank)
    }

    /**
     * Increases this node rank.
     */
    fun increaseRank() {
        rank++
    }

    fun setParent(e2Root: DisjointSetNode<E>) {
        parent = e2Root
    }
}
